<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    
</body>
<script>
    // 函数也是复杂数据，简单赋值，是浅拷贝

    function fn(){
        console.log(this)
    }

    var obj = {
        name:"obj",
        a:fn
    }
    var obj2 = {
        name:"obj2"
    }
    obj2.a = fn;

    console.log(obj.a === fn)

    // 默认绑定
    fn();

    console.log("===")

    // 隐式绑定
    obj.a();
    document.onclick = fn;
    obj2.a();

    console.log("===")

    // 隐式丢失
    var b = obj2.a;
    b();
    
    function abc(q){
        q();
    }
    abc( obj2.a );

    console.log("===")

    setTimeout( obj2.a , 1000);

    // 强制绑定
    fn.call(obj);
    fn.call(obj2);
    fn.call(window);
    fn.call("hello");

    console.log("===");

    // 修复隐式丢失
    setTimeout( obj2.a.bind(obj2) , 5000);

    var c = obj2.a.bind(obj2);
    c();

    console.log("===");

    // ==========

    var f = new fn();
    f.name = "new出来的对象"
    console.log(f);





</script>
</html>